<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta content="yes" name="apple-mobile-web-app-capable"/>
    <meta content="black" name="apple-mobile-web-app-status-bar-style"/>
    <meta content="telephone=no" name="format-detection"/>
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>echarts地图</title>
    <script src="../js/data.js"></script>
    <script src="../js/echarts.min.js"></script>
    <script src="../js/echarts-gl.min.js"></script>
    <script src="../js/jquery.min.js"></script>
</head>

<body>
<div class="viewport" id="home">
    <div class="echarts" id="echarts"></div>
</div>
</body>
<script>
    console.log(echarts.version);

    // 获取数据
    function getData() {
        $.get('../js/data.json', function (data) {
            getEcharts(data)
        });
    }

    // 渲染echarts
    function getEcharts(data) {
        var chartDom = document.getElementById('echarts');
        var myChart = echarts.init(chartDom);
        var nameMap = '地图数据';
        var mapData = []
        echarts.registerMap(nameMap, data);
        /*获取地图数据*/
        myChart.showLoading();
        var mapFeatures = echarts.getMap(nameMap).geoJson.features;
        myChart.hideLoading();
        mapFeatures.forEach(function (v, index) {
            // 地区名称
            mapData.push({
                name: v.properties.name,
                value: Math.random() * 100
            });
        });
        var optionMap = {
            toolbox: {
                show: true,
                feature: {
                    saveAsImage: {
                        show: true,
                        excludeComponents: ['toolbox'],
                        pixelRatio: 1
                    }
                }
            },
            geo3D: {
                map: nameMap,
                roam: true,
                itemStyle: {
                    areaColor: 'rgb(5,101,123)',
                    opacity: 1,
                    borderWidth: 0.8,
                    borderColor: 'rgb(62,215,213)'
                },
                label: {
                    show: true,
                    textStyle: {
                        color: '#fff', //地图初始化区域字体颜色
                        fontSize: 16,
                        opacity: 1,
                        backgroundColor: 'rgba(0,0,0,0)'
                        //backgroundColor: 'rgba(53,171,199,0)'
                    },
                },
                emphasis: { //当鼠标放上去  地区区域是否显示名称
                    label: {
                        show: true,
                        textStyle: {
                            color: '#fff',
                            fontSize: 16,
                            backgroundColor: 'rgba(0,23,11,0)'
                        }
                    }
                },
                //shading: 'lambert',
                light: { //光照阴影
                    main: {
                        color: '#20729b', //光照颜色
                        intensity: 1, //光照强度
                        //shadowQuality: 'high', //阴影亮度
                        shadow: false, //是否显示阴影
                        alpha: 55,
                        beta: 10

                    },
                    ambient: {
                        intensity: 0.3
                    }
                }
            },
            // series: serverdata
        };
        myChart.setOption(optionMap);

    }

    if (window.location.origin == 'file://') {
        setTimeout(() => {
            getEcharts(gdMap)
        }, 100)
    } else {
        getData()
    }
</script>
</html>
<style>
    html, body {
        padding: 0;
        margin: 0;
    }

    #home {
        width: 100%;
        height: 100%;
        background: #0d1551;
        position: fixed;
    }

    .echarts {
        width: 100%;
        height: 100%;
        background: #0d1551;
        position: fixed;
    }

    .info {
        position: fixed;
        top: 10px;
        left: 10px;
        z-index: 10;
        color: red;
    }

    .links {
        position: fixed;
        top: 10px;
        left: 10px;
        z-index: 10;

    }

    .links a {
        text-decoration: none;
        color: #fff;
    }
</style>
